//
//  RTJBankTypeListController.m
//  RuiTaiJinProject
//
//  Created by jayson on 2018/12/5.
//  Copyright © 2018年 leewei. All rights reserved.
//

#import "RTJBankTypeListController.h"
#import "RTJUserInfoCommntCell.h"

@interface RTJBankTypeListController ()
@property (weak, nonatomic) IBOutlet UITableView *tab;

@property (nonatomic,strong)NSMutableArray *data;

@end

@implementation RTJBankTypeListController

-(NSMutableArray *)data {
    if (!_data) {
        
        _data = [NSMutableArray array];
    }
    return _data;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"支持银行";
    self.tab.tableFooterView=[UIView new];
    self.tab.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tab.estimatedRowHeight=300;
    
    [self loadData];
    
}

-(void)loadData{
    
    [SVProgressHUD showWithStatus:nil];
    [self.view showEmptyViewWithStr:@"" image:nil callback:nil];
    
    [RTJNetWork asyncRequestWithURL:@"user/get_bank" params:nil method:GET zxCompletion:^(id data, NSInteger status, BOOL success, NSString *errorMsg) {
    
        [SVProgressHUD dismiss];
        [self.view removeEmptyView];
        
        if (success) {
            
            if ([data[@"status"]integerValue] == 1) {
                NSArray *arr = data[@"data"];
                
                [self.data removeAllObjects];
                [self.data addObjectsFromArray:arr];
                
                [self.tab reloadData];
            }else{
                
                [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",data[@"msg"]]];
                [self.view showEmptyViewWithStr:data[@"msg"] image:[UIImage imageNamed:@"kbylogo"] callback:^{
                    [self loadData];
                }];
            }
            
        }else{
            
            [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",errorMsg]];
            [self.view showEmptyViewWithStr:errorMsg image:[UIImage imageNamed:@"kbylogo"] callback:^{
                [self loadData];
            }];
        }        
        
    }];
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _data.count;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return UITableViewAutomaticDimension;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * ID = @"RTJUserInfoCommntCell";
    RTJUserInfoCommntCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
        if (!cell) {
            
            cell = [[NSBundle mainBundle] loadNibNamed:@"RTJUserInfoCommntCell" owner:self options:nil][2];
            
        }
        cell.data = _data[indexPath.row];   
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return  cell;
}

//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    
//    
//    [self.delegate bankName:_data[indexPath.row][@"name"] bankID:_data[indexPath.row][@"id"]];
//    [self.navigationController popViewControllerAnimated:YES];
//    
//}

@end
